package com.takeoutsystem.support;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;

/**
 * 字符串加密和解密
 */
public class EnCryptAndDeCryptUtil {
    /**
     * Base64算法加密字符串
     * @param originalStr
     * @return
     * @throws UnsupportedEncodingException
     */
    public static String encryptBase64(String originalStr) throws UnsupportedEncodingException {
        return Base64.getEncoder().encodeToString(originalStr.getBytes(StandardCharsets.UTF_8));
    }

    /**
     *  Base64算法解密字符串
     * @param secretStr
     * @return
     * @throws UnsupportedEncodingException
     */
    public static String decryptBase64(String secretStr) throws UnsupportedEncodingException {
        byte[] bytes=Base64.getDecoder().decode(secretStr);
        return new String(bytes,StandardCharsets.UTF_8);
    }
}
